import 'package:flutter_nb_net/flutter_net.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:tracker/pages/home/vip_service/model/vip_service_list_resp.dart';

import '../../../../common/constants/app_constants.dart';
import '../../../../common/log/x_logger.dart';
import '../../../../provider/global_provider.dart';
import '../../home/model/home_device_info_resp.dart';
import '../../record_history/model/device_details_resp.dart';

mixin OtherServiceMixin<T extends ConsumerStatefulWidget> on ConsumerState<T> {
  int actionType = 1;

  List<VipServiceData> highVipServiceData = []; //高清
  int highIndex = 0;
  int highPayIndex = 0;

  List<VipServiceData> recordVipServiceData = []; //录音
  int recordIndex = 0;
  int recordPayIndex = 0;

  /// 获取设备套餐列表
  Future<VipServiceListResp> getPackageList(int type) async {
    DeviceInfoVO deviceInfo = ref.read(deviceInfoProvider);

    final res = await get<VipServiceListResp, VipServiceListResp>(
        '$newBaseULr/package/list',
        queryParameters: {"type": type,'imei': deviceInfo.imei},
        decodeType: VipServiceListResp());
    return res.when(success: (resp) {
      return resp;
    }, failure: (String msg, int code) {
      XLogger.error('获取设备套餐列表失败：msg: $msg, code: $code');
      return VipServiceListResp();
    });
  }

  Future<DeviceDetailsResp>  getDeviceInfo() async {
    final deviceInfo = ref.watch(deviceInfoProvider);
    final res = await get<DeviceDetailsResp, DeviceDetailsResp>(
        '$newBaseULr/device/${deviceInfo.imei}',
        decodeType: DeviceDetailsResp());
    return res.when(success: (resp) {
      return resp;
    }, failure: (String msg, int code) {
      XLogger.error('获取设备信息失败：msg: $msg, code: $code');
      return DeviceDetailsResp();
    });
  }

  List<VipServiceData> getVipData(){
    if(actionType == 1 || actionType == 3){
      return highVipServiceData;
    } else {
      return recordVipServiceData;
    }
  }

  int getPayIndex(){
    if(actionType == 1 || actionType == 3){
      return highPayIndex;
    } else {
      return recordPayIndex;
    }
  }

  int getSelectIndex(){
    if(actionType == 1 || actionType == 3){
      return highIndex;
    } else {
      return recordIndex;
    }
  }
}
